package com.fs.user.controller;

import com.fs.common.domain.Result;
import com.fs.user.domain.dto.UserLoginFormDTO;
import com.fs.user.domain.dto.UserRegisterFormDTO;
import com.fs.user.domain.dto.UserUpdateDTO;
import com.fs.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "管理员相关接口")
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
public class UserController {

    private final IUserService userService;

    @ApiOperation("用户登录接口")
    @PostMapping("/login")
    public Result login(@RequestBody @Valid UserLoginFormDTO userLoginFormDTO) {
        return Result.ok(userService.login(userLoginFormDTO));
    }

    @ApiOperation("用户注册接口")
    @PostMapping("/register")
    public Result register(@RequestBody @Valid UserRegisterFormDTO userRegisterFormDTO) {
        return Result.ok(userService.register(userRegisterFormDTO));
    }

    @ApiOperation("退出")
    @PostMapping("/logout")
    public Result logout() {
        return Result.ok();
    }

    @ApiOperation("更新用户信息")
    @PutMapping("/{id}")
    public Result updateUser(@PathVariable("id") Long userId,
                                           @RequestBody @Valid UserUpdateDTO updateDTO) {
        return Result.ok(userService.updateUser(userId, updateDTO));
    }
}

